/**@FILE:OTSTableOperation.java
 * @AUTHOR:qingsheng.zheng
 * @DATE:2015-3-27 下午1:01:29*/
package com.fz.tool.aliyun.ots;

import java.util.List;

import com.aliyun.openservices.ots.OTSClient;
import com.aliyun.openservices.ots.model.CapacityUnit;
import com.aliyun.openservices.ots.model.CreateTableRequest;
import com.aliyun.openservices.ots.model.DeleteTableRequest;
import com.aliyun.openservices.ots.model.TableMeta;

/*******************************************
 * @COMPANY:alibaba
 * @CLASS:OTSTableOperation
 * @DESCRIPTION:
 * @AUTHOR:qingsheng.zheng
 * @VERSION:v1.0
 * @DATE:2015-3-27 下午1:01:29
 *******************************************/
public class OTSTableOperation {
	/**@description:OTS创建表
	 * @author:qingsheng.zheng
	 * @return:void
	 * @param client
	 * @param tableName
	 * @param primaryColumns
	 * @param wrcu
	 * @throws Exception*/
	
	private static void createTable(OTSClient client, String tableName,
			List<PrimaryColumn> primaryColumns, WRcu wrcu)
			throws Exception {
		TableMeta tableMeta = new TableMeta(tableName);
		for (int i = 0; i < primaryColumns.size(); i++) {
			PrimaryColumn column = primaryColumns.get(i);
			tableMeta.addPrimaryKeyColumn(column.getName(), column.getType());
		}
		// 将该表的读写CU都设置为100
		CapacityUnit capacityUnit = new CapacityUnit(wrcu.getReadcu(),
				wrcu.getWritecu());
		CreateTableRequest request = new CreateTableRequest();
		request.setTableMeta(tableMeta);
		request.setReservedThroughput(capacityUnit);
		client.createTable(request);
	}

	/**@description:OTS删除表
	 * @author:qingsheng.zheng
	 * @return:void
	 * @param client
	 * @param tableName
	 * @throws Exception*/
	
	private static void deleteTable(OTSClient client, String tableName)
			throws Exception {
		DeleteTableRequest request = new DeleteTableRequest();
		request.setTableName(tableName);
		client.deleteTable(request);
	}
}